import { createRouter, createWebHistory } from 'vue-router';

import Login from '../views/Login/login.vue';
import Layout from '../layouts/index.vue';
import WorkBench from '../views/WorkBench/index.vue';
import NotFound from '../views/404.vue';

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 登录路由
    {
      path: '/login',
      name: 'Login',
      component: Login,
      meta: { title: '登录' },
    },
    // 公共404页面路由
    {
      path: '/404',
      name: '404',
      component: NotFound,
      meta: { title: '404 页面未找到' },
    },
    // 带 Layout 的主路由
    {
      path: '/',
      redirect: '/layout', // 默认重定向到 layout
    },
    {
      path: '/layout',
      name: 'Layout',
      component: Layout,
      redirect: '/layout/workbench', // 默认子路由
      meta: { requiresAuth: true, title: '主界面' },
      children: [
        {
          path: 'workbench',
          name: 'WorkBench',
          component: WorkBench,
          meta: { title: '工作台', requiresAuth: true },
        },
        // 其他功能模块子路由可以继续添加
      ],
    },

    // 处理未定义路由，跳转到 404 页面
    {
      path: '/:catchAll(.*)',
      redirect: '/404',
    },
  ],
});

export default router;
